package com.century.sjt.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.century.sjt.R;
import com.century.sjt.entity.TransactionRecord;

import java.util.List;

/**
 * 订单适配器
 */
public class PaydayTransactionRecordAdapter extends BaseAdapter {

    private List<TransactionRecord> mDataList;
    private LayoutInflater mLayoutInflater;
    private Context context;

    public PaydayTransactionRecordAdapter(List<TransactionRecord> mDataList, Context context){
        this.mDataList=mDataList;
        this.context=context;
        mLayoutInflater=LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mDataList.size();
    }

    @Override
    public Object getItem(int i) {
        return mDataList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View convertView, ViewGroup viewGroup) {

        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            //由于我们只需要将XML转化为View，并不涉及到具体的布局，所以第二个参数通常设置为null
            convertView = mLayoutInflater.inflate(R.layout.sjt_pay_day_item, null);
            holder.tvPayTime= (TextView) convertView.findViewById(R.id.pay_yf_time);

            holder.tvPayJe= (TextView) convertView.findViewById(R.id.pay_yf_je);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        TransactionRecord transactionRecord=mDataList.get(i);

        holder.tvPayJe.setText("￥"+transactionRecord.getTxAmt());
//        holder.tvPayJs.setText(transactionRecord.getTradeType());
        holder.tvPayTime.setText(transactionRecord.getTxDate());



        //交易订单情况


//        if (holder.tvPayJs.getText().toString().equals("支付中")){
//            holder.tvPayJs.setTextColor(context.getResources().getColor(R.color.pay_success));
//        }else if (holder.tvPayJs.getText().toString().equals("支付失败")){
//            holder.tvPayJs.setTextColor(context.getResources().getColor(R.color.pay_error));
//        }else {
//            holder.tvPayJs.setTextColor(context.getResources().getColor(R.color.pay_dismiss));
//        }
        return convertView;
    }

    // ViewHolder用于缓存控件
    static class ViewHolder {
        public TextView tvPayJe;                //交易金额
        public TextView tvPayTime;             //交易时间
    }
}
